package cn.cs.service;

import cn.cs.mapper.CsMenuMapper;
import cn.cs.pojo.CsMenu;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
public class CsMenuService {

    @Resource
    private CsMenuMapper menuMapper;

    @RequestMapping(value = "/getCsMenuByRoleName", method = RequestMethod.POST)
    public List<CsMenu> getCsMenuByRoleName(@RequestParam("roleName") String roleName){
        return menuMapper.getCsMenuByRoleName(roleName);
    }

    @RequestMapping(value = "/getCsMenuById", method = RequestMethod.POST)
    public CsMenu getCsMenuById(@RequestParam("id") Long id) throws Exception{
        return menuMapper.getCsMenuById(id);
    }

    @RequestMapping(value = "/getCsMenuListByMap", method = RequestMethod.POST)
    public List<CsMenu> getCsMenuListByMap(@RequestBody Map<String, Object> param){
        return menuMapper.getCsMenuListByMap(param);
    }

    @RequestMapping(value = "/getAllMenu", method = RequestMethod.POST)
    public List<CsMenu> getAllMenu(){
        return menuMapper.getCsMenuListByMap(new HashMap<>());
    }

    @RequestMapping(value = "/getMenuTree", method = RequestMethod.POST)
    public List<CsMenu> getMenuTree(@RequestBody List<String> authoritiesList, @RequestBody List<String> ids){
        return menuMapper.getMenuTree(authoritiesList, ids);
    }

    @RequestMapping(value = "/getMenuList", method = RequestMethod.POST)
    public List<CsMenu> getMenuList(@RequestParam("pId") String pId, @RequestBody List<String> authoritiesList, @RequestBody List<String> ids){
        return menuMapper.getMenuList(pId, authoritiesList, ids);
    }

    @RequestMapping(value = "/getMenuByRoleId", method = RequestMethod.POST)
    public List<CsMenu> getMenuByRoleId(@RequestParam("id") String id){
        return menuMapper.getMenuByRoleId(id);
    }

    @RequestMapping(value = "/getCsMenuCountByMap", method = RequestMethod.POST)
    public Integer getCsMenuCountByMap(@RequestBody Map<String, Object> param) throws Exception{
        return menuMapper.getCsMenuCountByMap(param);
    }

    @RequestMapping(value = "/addCsMenu", method = RequestMethod.POST)
    public Integer addCsMenu(@RequestBody CsMenu csMenu) throws Exception{
        return menuMapper.insertCsMenu(csMenu);
    }

    @RequestMapping(value = "/modifyCsMenu", method = RequestMethod.POST)
    public Integer modifyCsMenu(@RequestBody CsMenu csMenu) throws Exception{
        return menuMapper.updateCsMenu(csMenu);
    }

    @RequestMapping(value = "/deleteCsMenuById", method = RequestMethod.POST)
    public Integer deleteCsMenuById(@RequestParam("id") Long id) throws Exception{
        return menuMapper.deleteCsMenuById(id);
    }

    @RequestMapping(value = "/getMenuListAll", method = RequestMethod.POST)
    public List<CsMenu> getMenuListAll(@RequestBody List<String> authoritiesList, @RequestBody List<String> ids){
        return menuMapper.getMenuListAll(authoritiesList, ids);
    }

}
